
/**
 * Write a description of class Category here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.*;
public class Category 
{
    ArrayList<Candidate> mCandidates, fCandidates; //general storage
    TreeSet<Candidate> mF, fF; //final male and female
    String name;
    
    public Category(String s){
        //this is the constructor for category, it takes the name
        name = s;
        mCandidates = new ArrayList<Candidate>();
        fCandidates = new ArrayList<Candidate>();
    }
    
    private void addCandidate(String n, boolean m){
        //this method adds either a new candidate or a vote to an existing candidate
        Candidate newb = new Candidate(n, m);
        newb.addVote();
        if(!m){
            for(Candidate h : fCandidates){
                if(h.equals(newb)){
                    h.addVote();
                    return;
                }                    
            }
            newb.addVote();
            fCandidates.add(newb);
        }else{
            for(Candidate h : mCandidates){
                if(h.equals(newb)){
                    h.addVote();
                    return;
                }                    
            }
            newb.addVote();
            mCandidates.add(newb);
        }
    }
    
    public void addVote(String n, boolean male){
        //this is the accessor method for adding votes
        if(n.equals("No Vote")){
            return;
        }
        addCandidate(n, male);
    }
    
    public Candidate[] topMen(){
        //this method returns the top 3 men for the category
        Candidate[] top = new Candidate[3];
        mToTreeSet();
        top[0] = mF.pollLast();
        top[1] = mF.pollLast();
        top[2] = mF.pollLast();
        return top;
    }
    
    public Candidate[] topWomen(){
        //this method returns the top 3 women for the category
        Candidate[] top = new Candidate[3];
        fToTreeSet();
        top[0] = fF.pollLast();
        top[1] = fF.pollLast();
        top[2] = fF.pollLast();
        return top;
    }

    public void mToTreeSet(){
        mF = new TreeSet();
        for(Candidate c: mCandidates){
            mF.add(c);
        }
    }
    
    public void fToTreeSet(){
        fF = new TreeSet();
        for(Candidate c: fCandidates){
            fF.add(c);
        }
    }
    
    public String getName(){
        return name;
    }
}